package com.luoke.util.myjdbc;

import java.util.List;

public interface BaseDao<T> {


    public default T selectOne(QueryWrapper<T> queryWrapper) {
         SQLExecute<T> sqlExecute = new SQLExecute<>();
        List<T> list = sqlExecute.executeQueryWrapper(queryWrapper);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    public default List<T> selectAll(QueryWrapper<T> queryWrapper) {
         SQLExecute<T> sqlExecute = new SQLExecute<>();

        List<T> list = sqlExecute.executeQueryWrapper(queryWrapper);
        return list;
    }

    public default T selectOneById(Long id, Class<T> clazz) {
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        T entity = sqlExecute.executeSelectOneById(id,clazz);
        return entity;
    }

    public default Integer updateById(T entity) {
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        return sqlExecute.executeUpdateById(entity);
    }

    public default Integer update(UpdateWrapper<T> updateWrapper) {
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        return sqlExecute.executeUpdateWrapper(updateWrapper);
    }

    public default void deleteByIds(List<Long> ids, Class<T> clazz) {
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        sqlExecute.executeDeleteByIds(ids,clazz);
    }
    public default Integer deleteById(Long id,Class<T> clazz){
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        return sqlExecute.executeDeleteById(id,clazz);
    }
    public default List<Long> insertBatch(List<T> entityList) {
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        return sqlExecute.executeInsertBatch(entityList);
    }
    public default Long insert(T entity) {
        SQLExecute<T> sqlExecute = new SQLExecute<>();
        return sqlExecute.executeInsert(entity);
    }
}
